<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加加减减</title>
</head>

<style>
    li button {
        margin-left: 20px;
    }
</style>

<body>
    <div id="app">
        <div v-for="item in List" :key="item.id">
            <li>{{item.num}} <button @click="del(item.id)">删除</button></li>
        </div>
        <button @click="add">生成</button>
    </div>

    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                List: [
                ]
            },
            methods: {
                add() {
                    this.List.push({
                        id: Date.now(),
                        num: Math.floor(Math.random() * 20) + 1
                    })
                },
                del(id) {
                    this.List = this.List.filter(item => item.id !== id)

                }
            }
        })
    </script>
</body>

</html>